const path = require('path');

function resolve(dir) {
    return path.join(__dirname, dir);
}

function publicPath() {
    if (process.env.NODE_ENV === 'production') {
        return "./"; // 修改为 "./"
    } else {
        return "/";
    }
}

module.exports = {
    publicPath: publicPath(),
    configureWebpack: {
        plugins: [
            new webpack.NormalModuleReplacementPlugin(
                /element-ui[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]zh-CN/,
                'element-ui/lib/locale/lang/en'
            )
        ],
        resolve: {
            alias: {
                '@': resolve('src')
            }
        }
    },
    lintOnSave: false,
    devServer: {
        host: "0.0.0.0",
        port: 8082,
        hot: true,
        https: false,
        proxy: {
            '/shared_power_bank_system': {
                target: 'http://localhost:8080/shared_power_bank_system/',
                changeOrigin: true,
                secure: false,
                pathRewrite: {
                    '^/shared_power_bank_system': ''
                }
            }
        }
    },
    chainWebpack(config) {
        config.module
            .rule('svg')
            .exclude.add(resolve('src/icons'))
            .end();
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]'
            })
            .end();
    }
};